package com.zyg.zlib.widget;

import android.content.Context;
import android.graphics.drawable.Drawable;

import androidx.annotation.ColorRes;
import androidx.annotation.DrawableRes;

public abstract class LableBuilder<T extends LableBuilder<T, E>, E> {
    Context context;
    Drawable icon;
    float iconScale = 1f;
    int gap;
    String text;
    int textSize;
    int textColor;
    boolean textBold;
    int leftPadding;
    int topPadding;
    int rightPading;
    int bottomPadding;

    boolean gradient;
    int gradientDirection;
    int gradientStartColor;
    int gradientEndColor;
    int fillColor = -1;

    int leftTopRadius;
    int rightTopRadius;
    int leftBottomRadius;
    int rightBottomRadius;

    boolean stroke;
    int strokeWidth;
    int strokeColor;

    LableBuilder(Context context) {
        this.context = context;
    }

    public T icon(@DrawableRes int iconRes) {
        this.icon = context.getDrawable(iconRes);
        return (T) this;
    }

    public T iconScale(float scale) {
        this.iconScale = scale;
        return (T) this;
    }

    /**
     * 图标和文字之间的距离
     *
     * @param gap
     * @return
     */
    public T gap(int gap) {
        this.gap = gap;
        return (T) this;
    }

    public T text(String text, int textSize, @ColorRes int textColorRes) {
        this.text = text;
        this.textSize = textSize;
        textColor = context.getResources().getColor(textColorRes);
        return (T) this;
    }

    public T textBold(boolean bold){
        this.textBold = bold;
        return (T) this;
    }

    public T padding(int left, int top, int right, int bottom) {
        this.leftPadding = left;
        this.topPadding = top;
        this.rightPading = right;
        this.bottomPadding = bottom;
        return (T) this;
    }

    /**
     * @param direction     0  :→
     *                      45 :↗
     *                      90 :↑
     *                      135:↖
     *                      180:←
     *                      225:↙
     *                      270:↓
     *                      315:↘
     * @param startColorRes
     * @param endColorRes
     * @return
     */
    public T gradient(int direction, @ColorRes int startColorRes, @ColorRes int endColorRes) {
        gradient = true;
        this.gradientDirection = direction;
        this.gradientStartColor = context.getResources().getColor(startColorRes);
        this.gradientEndColor = context.getResources().getColor(endColorRes);
        return (T) this;
    }

    public T fillColor(@ColorRes int fillColorRes) {
        this.fillColor = context.getResources().getColor(fillColorRes);
        return (T) this;
    }

    /**
     * 顺时针设置角度
     *
     * @param leftTop
     * @param rightTop
     * @param leftBottom
     * @param rightBottom
     * @return
     */
    public T radius(int leftTop, int rightTop, int leftBottom, int rightBottom) {
        this.leftTopRadius = leftTop;
        this.rightTopRadius = rightTop;
        this.leftBottomRadius = leftBottom;
        this.rightBottomRadius = rightBottom;
        return (T) this;
    }


    public T stroke(int strokeWidth, @ColorRes int strokeColor) {
        this.stroke = true;
        this.strokeWidth = strokeWidth;
        this.strokeColor = context.getResources().getColor(strokeColor);
        return (T) this;
    }

    public abstract E build();
}
